//
//  WBNavigationController.swift
//  weiboswift
//
//  Created by dingzhibing on 2017/2/28.
//  Copyright © 2017年 dingzhibing. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {


    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //隐藏默认的navigationbar
        navigationBar.isHidden = true
    }
    
    //所有push方法都会调用此方法  隐藏底部tabbar
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //避免向导航控制器添加tabvc时调用
        if childViewControllers.count > 0{
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? WBBaseViewController{
                
                var title = "返回"
                
                if childViewControllers.count == 1{
                    //显示首页标题
                    title = childViewControllers.first?.title ?? "返回"
                }
                //取出自定义的navItem
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent),isBack:true)
            }
        }
 
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func popToParent(){
        popViewController(animated: true)
    }

}


